//
//  DynamicNewsViewController.m
//  fitness-iOS
//
//  Created by 卢仕彤 on 2017/11/7.
//  Copyright © 2017年 卢仕彤. All rights reserved.
//

#import "DynamicNewsViewController.h"
#import "DynamicViewModel.h"

#define kDynamicHeadCell  @"DynamicHeadCell"
#define kSDCycleScrollCell @"SDCycleScrollCell"
#define kDynamicPlanCell @"DynamicPlanCell"
#define kDynamicStoryCell @"DynamicStoryCell"

@interface DynamicNewsViewController (){
    NSMutableArray *_sections;
    
}
@property (nonatomic, strong) SDCycleScrollView *sdCyView;

@end

@implementation DynamicNewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self registCell];
    self.tableView.canReload =  YES;
}


- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.tableView.frame = CGRectMake(0, -20,Main_Screen_Width, Main_Screen_Height);
}

- (void)registCell {
    [self.tableView registerClass:[SDCycleScrollCell class] forCellReuseIdentifier:kSDCycleScrollCell];
    [self.tableView registerClass:[DynamicPlanCell class] forCellReuseIdentifier:kDynamicPlanCell];
}

- (NSArray *)customSections {
    
    if (_sections == nil) {
        _sections = [NSMutableArray array];
        // 头部的cell主要包括上面的webView
        MCUTableCustomSection *sec = [MCUTableCustomSection createWithTarget:self];
        sec = [MCUTableCustomSection createWithTarget:self];
        sec.cellForRowAtIndexSelector = @selector(cellViewForDyHeadCell:);
        sec.heightForCellSelector = @selector(heightCellForDyHeadCell:);
        sec.cellSelectedSelector = @selector(selectedForDyHeadCell:);
        [_sections addObject:sec];
        
        //中间的cell
        sec = [MCUTableCustomSection createWithTarget:self];
        sec.numberOfRowsSelector = @selector(numberOfRowForDyCenterCell:);
        sec.cellForRowAtIndexSelector = @selector(cellViewForDyCenterCell:);
        sec.heightForCellSelector = @selector(heightCellForDyCenterCell:);
        sec.cellSelectedSelector = @selector(selectCellForDyCenterCell:);
        [_sections addObject:sec];

        //底部的cell
        sec = [MCUTableCustomSection createWithTarget:self];
        sec.cellForRowAtIndexSelector = @selector(cellViewForDyBottomCell:);
        sec.heightForCellSelector = @selector(heightCellForDyBottomCell:);
        sec.cellSelectedSelector = @selector(selectCellForDyeBottomCell:);
        [_sections addObject:sec];
    }
    return _sections;
    
}

- (NSNumber *)heightCellForDyHeadCell:(NSIndexPath *)indexPath {
    return  @200;
}

- (void)selectedForDyHeadCell:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (UITableViewCell *)cellViewForDyHeadCell:(NSIndexPath *)indexPath {
    UIImage *image = [UIImage imageNamed:@"home_bar_scan"];
    UIImage *image1 = [UIImage imageNamed:@"home_bar_scan"];
    UIImage *image2 = [UIImage imageNamed:@"home_bar_scan"];
    NSArray *array = @[image,image1,image2];
    
    SDCycleScrollCell *cell = [[SDCycleScrollCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kSDCycleScrollCell imageArray:array];
    
    return cell;
}

- (NSNumber *)numberOfRowForDyCenterCell:(NSIndexPath *)indexPath {
    return  @1;
}

- (UITableViewCell *)cellViewForDyCenterCell:(NSIndexPath *)indexPath {
    DynamicPlanCell *cell = [[DynamicPlanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kDynamicPlanCell];
    cell.titleLabel.text = @"训练计划";
    return cell;
}

- (NSNumber *)heightCellForDyCenterCell:(NSIndexPath *)indexPath {
    return  @180;
}

- (void)selectCellForDyCenterCell:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma -mark ------------------底部的cell----------------------

- (UITableViewCell *)cellViewForDyBottomCell:(NSIndexPath *)indexPath {
    DynamicStoryCell *cell = [[DynamicStoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kDynamicStoryCell];
    cell.titleLabel.text = @"任务故事";
    return cell;
}

- (NSNumber *)heightCellForDyBottomCell:(NSIndexPath *)indexPath {
    return  @200;
}

- (void)selectCellForDyeBottomCell:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
